﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Remote_Scripts_Client
{
    public partial class OptionWindow : Form
    {
        public OptionWindow()
        {
            InitializeComponent();

            this.addressTextBox.Text = NetworkManager.Address;
            this.portTextBox.Text = NetworkManager.Port;
        }

        private void saveButton_Click(object sender, EventArgs e)
        {
            int u = 0;

            if (int.TryParse(this.portTextBox.Text, out u) == false)
            {
                MessageBox.Show("Błędna wartość portu!");
                return;
            }

            if (u > 65535)
            {
                MessageBox.Show("Za duża wartość portu!");
                return;
            }

            NetworkManager.Address = this.addressTextBox.Text;
            NetworkManager.Port = this.portTextBox.Text;

            MainWindow.Window.NetworkManager.Disconnect();
            MainWindow.Window.NetworkManager = new NetworkManager();

            this.Close();
        }
    }
}
